<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Hello React</title>
</head>
<body>

  <div id="root"></div>

  <script crossorigin src="../lib/react.js"></script>
  <script crossorigin src="../lib/react-dom.js"></script>
  <script src="../lib/babel.js"></script>
  
  <script type="text/babel">
    
    class App extends React.Component {
      
      constructor() {
        super()
        this.state = {
          students:[
            {
              id: 0,
              name: '小李',
              score: 100
            },
            {
              id: 1,
              name: '小李1',
              score: 98
            },
            {
              id: 2,
              name: '小李2',
              score: 87
            },
            {
              id: 3,
              name: '小李3',
              score: 91
            }
          ]
        }
      }

      render() {
        const { students } = this.state

        // 分数大于90的学生
        const filterStudents = students.filter(item => {
          return item.score > 90
        })
        // 只展示大于90的前两个
        const sliceStudents = filterStudents.slice(0, 2)
        return (
          <div>
            <h2>学生列表</h2>
            <ul>           
              {
                students.filter(item => item.score>90).slice(0,2).map(item => 
                <li key={item.id}>
                  <div>学号：{item.id}</div>
                  <div>姓名：{item.name}</div>
                  <div>分数：{item.score}</div>
                </li>)
              }
            </ul>
          </div>
        )
      }
    }

    // 将组件渲染到页面
    const root = ReactDOM.createRoot(document.querySelector("#root"))
    root.render(<App />)
  </script>
</body>
</html>